package cn.wj.school.server.net.context;

import cn.wj.school.common.dto.BaseMsg;
import cn.wj.school.common.manager.ManagerBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 玩家请求消息任务
 * 
 * @author kingston
 *
 */
public class CmdTask extends DispatchTask {

    private static Logger logger = LoggerFactory.getLogger(CmdTask.class);

    private long userId;
    private IoSession session;
    private BaseMsg msg;

    public static CmdTask valueOf(int distributeKey, IoSession session, BaseMsg msg) {
        CmdTask msgTask = new CmdTask();
        msgTask.dispatchKey = distributeKey;
        msgTask.session = session;
        msgTask.msg = msg;

        return msgTask;
    }

    public long getUserId() {
        return userId;
    }

    @Override
    public void run() {
        try {
            ManagerBuilder.getManagerBuilder().exec(msg, session.getChannel());
        } catch (Exception e) {
            logger.error("业务处理出现异常", e);
        }
    }

}
